﻿package com.rragona.utils.genericComponents 
{
	/**=========================================================================
	 * @author 		rragona
	 * @contact		rragona@soe.sony.com	
	 * @usage		
	 * 
	 * @history		
	 *		[x/x] class created.
	 *///=======================================================================
	
	/**=========================================================================
	 * IMPORTS 
	 *///=======================================================================

	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	/**=========================================================================
	 * CLASS 
	 *///=======================================================================
	
	
	public class BasicButton extends MovieClip
	{
		
		/**=====================================================================
		 * Public Variables
		 *///===================================================================
		
		
		/**=====================================================================
		 * Private Variables
		 *///===================================================================
		
		private var _selected:Boolean;
		
		/**=====================================================================
		 
		 * Constructor
		 
		 *///===================================================================
		
		public function BasicButton() 
		{
			buttonMode = true;
			
			initListeners();
		}
		
		public function set selected(value:Boolean):void
		{
			_selected = value;
			
			if (value)
			{
				mouseChildren = false;
				mouseEnabled = false;
				gotoAndStop("selected");
			}
			else
			{
				mouseChildren = true;
				mouseEnabled = true;
				gotoAndStop("up");
			}
		}
		
		/**=====================================================================
		 * Private Methods
		 *///===================================================================
		
		private function initListeners():void
		{
			addEventListener(MouseEvent.ROLL_OVER, simpleStateHandler);
			addEventListener(MouseEvent.ROLL_OUT, simpleStateHandler);
			addEventListener(MouseEvent.MOUSE_DOWN, simpleStateHandler);
			addEventListener(MouseEvent.MOUSE_UP, simpleStateHandler);
		}
		
		private function simpleStateHandler(e:MouseEvent):void
		{
			if (!_selected)
			{
				switch(e.type)
				{
					case MouseEvent.ROLL_OVER:
						gotoAndStop("over");
						break;
					case MouseEvent.ROLL_OUT:
						gotoAndStop("up");
						break;
					case MouseEvent.MOUSE_DOWN:
						gotoAndStop("down");
						break;
					case MouseEvent.MOUSE_UP:
						gotoAndStop("over");
						break;
				}
			}
		}
		
	}
	
}